package other.edan.erp.utils;

/**
 * 响应数据(结果)最外层对象
 */
public class ResultVo<T> {

    /** 状态码 "状态码（200成功、-1错误）"*/
    private Integer code;

    /** 提示信息 */
    private String msg;


    /** 响应数据 */
    private T data;

    public ResultVo() {}

    public ResultVo(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResultVo<T> success() {
        ResultVo<T> result = new ResultVo<T>();
        result.code = 200;
        return result;
    }

    @Override
    public String toString() {
        return "ResultVo{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static <T> ResultVo<T> success(T object) {
        ResultVo<T> result = new ResultVo<T>();
        result.data = object;
        result.code = 200;
        return result;
    }

    public static <T> ResultVo<T> success(String msg, T object) {
        ResultVo<T> result = new ResultVo<T>();
        result.data = object;
        result.msg = msg;
        result.code = 200;
        return result;
    }

    public static <T> ResultVo<T> error(String msg) {
        ResultVo result = new ResultVo();
        result.msg = msg;
        result.code = -1;
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
